<?php
declare (strict_types=1);

namespace app\admin\controller;

use app\BaseController;
use app\model\Admins;
use app\model\Coupon;
use app\model\Order;
use app\model\Users;

class Index extends BaseController
{
    /**
     * 后台面板
     * @return \think\response\Json
     */
    public function panel()
    {
        $school_id=request()->param('school_id');
        $data['teacher']=Admins::where('belong_school',$school_id)->count();
        $data['student']=\app\model\Student::where('school_id',$school_id)->count();
        $data['invoice']=\app\model\Invoice::where('school_id',$school_id)->where('status',1)->count();
        return $this->success($data);
    }


    /**
     * 走線圖
     * @return void
     */
    public function graph()
    {
        $months = array();
        $school_id = request()->param('school_id');
        $b = array(); // 用于保存每个月份的总金额

        for ($i = 1; $i <= 12; $i++) {
            $months[] = $i;
            $monthString = date('Y-m', mktime(0, 0, 0, $i, 1)); // 将整数月份转换为字符串
            $totalAmount = \app\model\Proceeds::where('school_id', $school_id)
                ->whereMonth('create_time', $monthString)
                ->sum('money');
            $b[] = $totalAmount; // 将每个月份的总金额添加到数组中
        }

        return $this->success($b);
    }
}
